var app=getApp();
var ux = require('../../../../lib/ux.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {    
    addressA: { address: '请选择坐标' },
    code:'',
    mobile:'',
	action:"",
    saveUrl:'/api/delivery/deliveryRegister.do',
	submit:"{{submit}}"
  },
  deletThis: function () {
    this.setData({
      addressA: { address: '请选择坐标' },
    })
  },
  onChangeAddress: function (e) {
    wx.navigateTo({
      url: "/pages/member/tab3/adress/positon"
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      password: options.password,
      code:options.code,
      mobile:options.mobile
    })
  },
  
  onForm:function(event){
	if(this.data.submit){
		  var $this = this;
		  var dataset = event.currentTarget.dataset;
		  ux.request(this.data.submit,detail.value,function(protocol){
				if(protocol.success){
					if(dataset.url){
						wx.redirectTo(dataset.url);
					}
				}
		  },true);
	 }
  },
  onTap:function(event){
	  var dataset = event.currentTarget.dataset;
	  var data = this.data;
	  if(dataset.key && dataset.val){
		  data[dataset.key] = dataset.val;
	  }
	  this.setData(data);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
  toast: function (params) {
    if (typeof (params) == "string") {
      params = { content: params };
    }
    this.setData({
      toast: params.content
    });
    var THIS = this;
    setTimeout(function () {
      THIS.setData({
        toast: false
      });
      if (params.complete) {
        params.complete();
      }
    }, params.time || 3000);
  },
  toast: function (params) {
    if (typeof (params) == "string") {
      params = { content: params };
    }
    this.setData({
      toast: params.content
    });
    var THIS = this;
    setTimeout(function () {
      THIS.setData({
        toast: false
      });
      if (params.complete) {
        params.complete();
      }
    }, params.time || 3000);
  },
  tijiao:function(){
    var $this = this;
    if ($this.data.addressA.address == "请选择坐标") {
       this.toast("请选择地址")
       return false;
    }
  
  
    var params = { mobile: this.data.mobile, code: this.data.code, longitude: this.data.addressA.longitude, latitude: this.data.addressA.latitude, coordinate: this.data.addressA.address, password:this.data.password}
    ux.request(this.data.saveUrl, params, function (protocol) {
     if(protocol.data.type==1){
       var pages = getCurrentPages();
       var currPage = pages[pages.length - 1]; //当前页面
       var prevPage = pages[pages.length - 2]; //上一个页面
       wx.navigateBack({
         delta: 4
       })
     }else{
       $this.toast(protocol.data.msg);
     }
    }, true);
  }
})
